<?php

class AddressBusiness {

	public function getAddressByCep($cep){
		$db = Zend_Db_Table::getDefaultAdapter();

		$select = $db->fetchRow("select distinct * from location_address la
								inner join location_address_type lt
								on lt.idt_address_type = la.idt_address_type
								inner join location_district ld
								on ld.idt_district = la.idt_district
								inner join location_city lc
								on lc.idt_city = ld.idt_city
								inner join location_state ls
								on ls.idt_state = lc.idt_state
								where zip_code = '".$cep."' ");

		return $select;
	}

	public function getAllStates(){
		try {
			$db = Zend_Db_Table::getDefaultAdapter();

			$select = $db->fetchAll("SELECT * FROM location_state");

			return $select;
		} catch (Exception $e) {
		}
	}

	public function getCityByCepStreet($cep, $city){

		$db = Zend_Db_Table::getDefaultAdapter();

		$select = $db->fetchRow("select distinct lc.idt_city from location_address la
								inner join location_district ld
								on ld.idt_district = la.idt_district
								inner join location_city lc
								on lc.idt_city = ld.idt_city
								where zip_code = '".str_replace("-", "", $cep)."' or lower(des_city) = lower('".$city."')");
		return $select;
	}
	
	public function getCityByState($state){
		$db = Zend_Db_Table::getDefaultAdapter();

		$select = $db->fetchAll("select * from location_city lc
								inner join location_state ls
								on ls.idt_state = lc.idt_state
								where ls.des_state = ?", $state);
		return $select;
	}

}